
package com.horizon.mobile.view;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;

import com.horizon.mobile.R;
import com.horizon.mobile.model.Agent;

import java.util.Map;

import zuo.biao.library.base.BaseModel;
import zuo.biao.library.base.BaseView;
import zuo.biao.library.util.StringUtil;

public class FlowTransferView extends BaseView<Agent> implements OnClickListener {
	private static final String TAG = "AgentViewSet";
	Map<String, Agent> isCheckedMap;

	public FlowTransferView(Activity context, Resources resources,
                            Map<String, Agent> isCheckedMap) {
		super(context, resources);
		this.isCheckedMap = isCheckedMap;
	}

	public TextView tvFlowName;
	public CheckBox cvCheckBox;
	public TextView tvType;
	public TextView tvAgentPersion;
	public TextView tvBigenTime, tvEndTime;

	@SuppressLint("InflateParams")
	@Override
	public View createView(LayoutInflater inflater) {
		convertView = inflater.inflate(R.layout.agent_view_for_set, null);
		tvFlowName = findViewById(R.id.tvFlowname, this);
		tvType = findViewById(R.id.tvType, this);
		cvCheckBox = findViewById(R.id.isCheakBox);
		tvAgentPersion = findViewById(R.id.tvAgentPersion, this);
		tvBigenTime = findViewById(R.id.tvBigenTime, this);
		tvEndTime = findViewById(R.id.tvEndTime, this);
		return convertView;
	}

	@Override
	public void bindView(final Agent data) {

		this.data = data;
		cvCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
				if (isChecked) {
					isCheckedMap.put(data.getFlowId(), data);
				} else {
					isCheckedMap.remove(data.getFlowId());
					// isCheckedMap.put(data.getFlowName()+"~"+data.getFlowId(),false);
				}

			}
		});
		tvFlowName.setText(StringUtil.getTrimedString(data.getFlowName()));
		tvType.setText(StringUtil.getNoBlankString(data.getTitle()));
		tvAgentPersion.setText(StringUtil.getNoBlankString(data
				.getOldName()));
		tvBigenTime.setText(data.getBeginDate());
		tvEndTime.setText(data.getEndDate());
		cvCheckBox.setChecked(false);
	}

	@Override
	public void onClick(View v) {
		if (BaseModel.isCorrect(data) == false) {
			return;
		}
		switch (v.getId()) {
		}
	}
}